using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

using SmartRename.Interfaces;

namespace SmartRename
{
    public partial class FileList : UserControl
    {
        public FileList()
        {
            InitializeComponent();
        }

        private List<RenameFile> _renameList;
        public List<RenameFile> RenameList
        {
            get { return _renameList; }
            set 
            { 
                _renameList = value;
                this.dgFileList.DataSource = this._renameList;
                SetupGrid();
            }
        }

        private void SetupGrid()
        {
            List<string> columnsToHide = new List<string>();
            columnsToHide.Add("OriginalNameWithoutExtension");
            columnsToHide.Add("FullPath");
            foreach (string columnToHide in columnsToHide)
            {
                if (this.dgFileList.Columns.Contains(columnToHide))
                {
                    this.dgFileList.Columns[columnToHide].Visible = false;
                }
            }
        }

        private ISmartRename SmartRename
        {
            get 
            {
                Program.SmartRename.RenameFiles = this.RenameList;
                return Program.SmartRename;
            }
        }

        private void Rename()
        {
            this.SmartRename.RenameFormat = this.txtRenameFormat.Text;
            if (this.chkKeepExt.Checked)
            {
                this.SmartRename.RenameFormat += ".%ext%";
            }
            this.SmartRename.SetNewNames();
            this.dgFileList.Invalidate();
        }

        private void cmdRename_Click(object sender, EventArgs e)
        {
            this.SmartRename.CommitNewNames();
        }

        private void cmdPreview_Click(object sender, EventArgs e)
        {
            this.Rename();
        }
    }
}
